package com.tensquare.friend.dao;

import com.tensquare.friend.pojo.Friend;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

//JpaRepository<Friend,String>  当查询为联合主键是用friend即可,
// 这里我们查询不使用联合主键查询,使用Sql查询,直接用String即可
public interface FriendDao extends JpaRepository<Friend,String> {

    //根据userid/friendid  查询数量
    @Query("select count(f) from Friend f where friendid = ?2 and userid = ?1")
    Long getCountByUserIdAndFriendId(String userId,String friendId);


    @Modifying
    @Query("update Friend set islike = ?3 where friendid = ?2 and userid = ?1")
    void updateIsLike( String userId,String friendId, String islike);

    @Modifying
    @Query("delete from Friend where friendid = ?2 and userid = ?1")
    void deleteByFriendidAndAndUserid(String userId,String friendId);
}
